from flask_restful import Resource

from restful.api__.session import login_required_current_user_generate, \
    pid_required_target_post_generate
from restful.model.query import QueryOneInstance
from restful.model.tables import Blog, Check
from restful.response import ResponseSuccess, ResponseForbidden


class PostInfoPublished(Resource):
    @login_required_current_user_generate
    @pid_required_target_post_generate
    def get(self,target_post,current_user):
        check = QueryOneInstance(Check,{'pid': target_post.id,'checked':True,'passed':True})

        if not check:
            return ResponseForbidden("帖子暂未审核或未通过，无法公开查看")

        return ResponseSuccess(data={
            'pid':target_post.id,
            'uid':target_post.uid,
            'time':target_post.time,
            'sort':target_post.sort,
            'content':target_post.content,
            'title':target_post.title,
        })